package com.igeek.boot.controller;

import com.igeek.boot.anno.WMSLoganno;
import com.igeek.boot.config.LoginUser;
import com.igeek.boot.result.Result;
import com.igeek.boot.service.IMenuService;
import com.igeek.boot.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @package com.igeek.boot.controller
 * @Description 菜单控制层
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2023/12/27 13:53
 */
//@CrossOrigin
@RestController
@RequestMapping("/wisdom_factory/menu")
@Api(tags = "菜单表接口")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    //@WMSLoganno(module = "菜单",operation = "查询菜单表信息")
    @ApiOperation("查询菜单表所有信息")
    @GetMapping("/findAll")
    //@PreAuthorize("authentication.principal.username == 'admin'")
    public Result findAll(){
        //获取当前认证信息
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Integer userId = loginUser.getUser().getId();
        List<MenuVO> list = menuService.finAll(userId);
        if(!CollectionUtils.isEmpty(list)){
            return new Result(true,"菜单查询成功",list);
        }
        return new Result(false,"菜单查询失败");
    }
}
